package d13_tz.d4_blocking_queue;

import java.util.concurrent.ArrayBlockingQueue;

public class Foodie extends Thread{
    private final ArrayBlockingQueue<String> queue;

    public Foodie(ArrayBlockingQueue<String> queue) {
        this.queue = queue;
    }
    @Override
    public void run() {
        //完成池面条的事情
        while(true){
            String food = null;
            try {
                food = queue.take();//底层是有锁的
                System.out.println("贪吃,吃了"+food);//注意--->是放在锁外面的,可能会出错
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

        }

    }
}
